package com.yzy.fly.mapper;

import com.yzy.fly.entity.role.FlyAttributeWidget;
import com.yzy.fly.kernel.mapper.FlyBasicMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

@Mapper
public interface FlyAttributeWidgetMapper extends FlyBasicMapper<FlyAttributeWidget> {

    @Select("select * from fly_attribute_widget a where 1=1 ")
    List<FlyAttributeWidget> selectAllList();

    @Select({"select * from fly_attribute_widget a where 1=1 and a.attrId = #{attrId}"})
    FlyAttributeWidget selectOneByAttrId(@Param("attrId") Integer attrId);

    @Select({"select * from fly_attribute_widget a where 1=1 and a.systemId = #{systemId}"})
    List<FlyAttributeWidget> selectAllBySystemId(@Param("systemId") Integer systemId);

    @Select("select * from fly_attribute_widget a where 1=1 and a.defModelId = #{defModelId} and a.systemId = #{systemId}")
    List<FlyAttributeWidget> selectAllByDefModelIdAndSystemId(@Param("defModelId") Integer defModelId, @Param("systemId") Integer systemId);

    @Select("select * from fly_attribute_widget a where 1=1 and a.modelId = #{modelId} and a.systemId = #{systemId}")
    List<FlyAttributeWidget> selectAllByModelIdAndSystemId(@Param("modelId") Integer modelId, @Param("systemId") Integer systemId);


    @Select({"<script>"+
        "select * from fly_attribute_widget a where 1=1 " +
        "and a.id in "+
        "<foreach item='id' index='index' collection='ids' open='(' separator=',' close=')'>"+
        "#{id}"+
        "</foreach>"+
        "</script>"
    })
    List<FlyAttributeWidget> selectAllByIds(@Param("ids") int[] ids);

    @Delete("delete a from fly_attribute_widget a where 1=1 and a.modelId = #{modelId}")
    int deleteByModelId(@Param("modelId") Integer modelId);

    @Delete({"<script>"+
            "delete a from fly_attribute_widget a where 1=1 " +
            "and a.id in "+
            "<foreach item='id' index='index' collection='ids' open='(' separator=',' close=')'>"+
            "#{id}"+
            "</foreach>"+
            "</script>"
    })
    int deleteByIds(@Param("ids") int[] ids);

    @Delete({"delete a from fly_attribute_widget a where 1=1 ",
            "and a.attrId = #{attrId}"
    })
    int deleteByAttrId(@Param("attrId")int attrId);

    /**
     * 批量插入（mysql）
     * @param entityList
     * @return
     */
    Integer insertBatchSomeColumn(Collection<FlyAttributeWidget> entityList);
}
